import { Controller } from 'egg';
import ApiResult from '../apiModel/apiModel';

export class RequestData<T> {
    param: T;
    userInfo: any;
}

export default class BaseController extends Controller {

    /**
    * 获取前端post信息
        * @param request
     * @returns {RequestData<T>}
     */
    async getData<T>(param: any): Promise<RequestData<T> | null> {
        let requestData = new RequestData<T>();
        if (!param || !param['userId']) {
            return null;
        }
        return requestData;
    }
    public async returnData(success: boolean, data: any, err: any): Promise<string> {
        let ret = new ApiResult();
        ret.success = success;
        ret.msg = err;
        if (!success && err != null) {
            if (err.stack != null) {
                console.log(err.stack)
            }
            ret.msg = err.toString();
        }
        ret.data = data;
        return JSON.stringify(ret);
    }
}
